<template>
  <div>
    <el-dropdown trigger="click" @command="changeLang">
      <svg-icon
        icon-class="language"
        style="
          color: #fff;
          width: 23px;
          height: 23px;
          position: relative;
          top: 5px;
        "
      >
      </svg-icon>
      <el-dropdown-menu slot="dropdown">
        <el-dropdown-item command="zh" :disabled="this.$i18n.locale === 'zh'">
          中文
        </el-dropdown-item>
        <el-dropdown-item
          divided
          command="en"
          :disabled="this.$i18n.locale === 'en'"
        >
          en
        </el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
  </div>
</template>

<script>
import Cookie from 'js-cookie'
export default {
  methods: {
    changeLang(type) {
      // 先把语言存入session
      Cookie.set('language', type)
      // 通过$t方法切换语言
      this.$i18n.locale = type
    }
  }
}
</script>

<style></style>
